package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import flc.ast.AppConfig;
import flc.ast.R;
import flc.ast.activity.StoryActivity;
import flc.ast.databinding.FragmentCultureBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.FastClickUtil;
import stark.common.bean.StkResBean;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link CultureFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class CultureFragment extends BaseNoModelFragment<FragmentCultureBinding> {

    private StkResBean stkResBean;

    @Override
    protected int onCreate() {
        return R.layout.fragment_culture;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        mDataBinding.ivStory.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        if (FastClickUtil.isFastClick()) return;
        switch (v.getId()){
            case R.id.ivStory:
                startActivity(StoryActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData(){
        StkResApi.getTagResourceList(this, AppConfig.CULTURE_DATA, StkResApi.createParamMap(0, 10), false, new IReqRetCallback<List<StkResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkResBean> result) {
                if (success){
                    if (result != null && result.size() > 0) {
                        stkResBean=result.get(0);
                        mDataBinding.webView.loadUrl(stkResBean.getUrl());
                    }
                }
            }
        });
    }

}